﻿<!DOCTYPE html>
<html>
<head>
<title>新建日程</title>
<meta name="Keywords" content="关键字">
<meta name="Description" content="内容">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
<meta content="no-cache,must-revalidate" http-equiv="Cache-Control">
<meta content="telephone=no, address=no" name="format-detection">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta content="no-cache" http-equiv="pragma">
<meta content="0" http-equiv="expires">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/style.css" media="all"> 
<script type="text/javascript" src="__PUBLIC__/home/js/jquery-1.9.1.min.js"></script> 
<script type="text/javascript" src="__PUBLIC__/home/js/size.js"></script>
<!--日期插件-->
<script src="__PUBLIC__/home/js/mobiscroll.2.13.2.js"></script>
<link href="__PUBLIC__/home/css/mobiscroll.2.13.2.css" rel="stylesheet" />
<!--联动插件-->
<link rel="stylesheet" type="text/css" href="__PUBLIC__/home/css/mobileSelect.css" media="all"> 
<script type="text/javascript" src="__PUBLIC__/home/js/mobileSelect.js"></script> 
<!--多选--> 
<script type="text/javascript" src="__PUBLIC__/home/js/multi.js"></script> 
</head>
<body>
<header class="header">
    <div class="box">
        <div class="hleft"><a href="#" onClick="javascript :history.back(-1);" class="tclose"></a></div>
        <h1>新建日程</h1>
        <div class="hright"><a class="tkeep"></a></div>
    </div>
</header>
<div class="formlist">
    <div class="textarea frame"><textarea id="content" name="" cols="" rows="" placeholder="请输入日程内容"></textarea></div>
    <ul class="flexlist frame">
        <li>
            <i class="ico-01 ico"></i>
            <div class="t">项目</div>
            <div class="intxt"><div  id="trigger1" name="xm" class="xinput ico-arrow">&nbsp;</div></div>
        </li>
        <li>
            <i class="ico-02 ico"></i>
            <div class="t">日程截止时间</div>
            <div class="intxt"><input id="datetime" class="xinput ico-arrow" name="" type="text" value=""></div>
        </li>
        <li>
            <i class="ico-03 ico"></i>
            <div class="t">跟进人员</div>
            <div class="intxt multsel1">
                <input class="xinput ico-arrow" id="follow" name="" type="text" value="" placeholder="请选择跟进人员" readonly="readonly">
                
                <!---->
                <div class="selistbox">
                <div class="selist">
                    <div class="hd"><h3>跟进人员</h3><div class="mclose">确定</div></div>
                    <foreach name="data" item="vo">
                    <a class="seitem" value="{$vo['id']}">{$vo['nickname']}</a>
                    </foreach>
                </div>
                </div>    
                <!---->
            </div>
        </li>
        <li>
            <i class="ico-04 ico"></i>
            <div class="t">抄送人员</div>
            <div class="intxt multsel2">
                <input class="xinput ico-arrow" name="" type="text" id="cc" value="" placeholder="请选择抄送人员" readonly="readonly">
                <!---->
                <div class="selistbox">
                <div class="selist">
                    <div class="hd"><h3>抄送人员</h3><div class="mclose">确定</div></div>
                    <foreach name="data" item="vo">
                    <a class="seitem" value="{$vo['id']}">{$vo['nickname']}</a>
                    </foreach>
                </div>
                </div>    
                <!---->
            </div>
        </li>
    </ul>
    <input type="hidden" id='xm' value=''>
    <input type="hidden" id='xmid' value=''>
    <input type="hidden" id='sel1' value=''>
    <input type="hidden" id='sel2' value=''>
    <div class="textarea frame"><textarea id="remark" name="" cols="" rows="" placeholder="请输入备注"></textarea></div>
</div>
<include file="Public/footer" />

<!--弹出折叠项目-->
<div class="popbox" style="display:block;">
    <div class="popbd">
        <div class="hd"><h3>项目</h3><div class="mclose">确定</div></div>
        <ul class="diytree">
        <span class="control">收起/展开</span>
            <foreach name="info" item="vo"> 
            <if condition="$vo['flag'] eq 1">      
            <li><label><img src="__PUBLIC__/home/images/ico-.png">{$vo['value']}</label>
                <ul>
                    <foreach name="vo.childs" item="vo1">
                    <if condition="$vo1['flag'] eq 1">  
                    <li><label><img src="__PUBLIC__/home/images/ico-.png">{$vo1['value']}</label>
                        <ul>
                            <foreach name="vo1.childs" item="vo2">  
                            <li><label><input name="" type="checkbox" value="{$vo2['id']}" title="{$vo2['title']}">{$vo2['value']}</label></li>
                            </foreach>
                        </ul>
                    </li>
                    <else />
                    <li><label><input name="" type="checkbox" value="{$vo1['id']}" title="{$vo1['title']}">{$vo1['value']}</label>
                    </if>
                    </foreach>    
                    </li>
                </ul>
            </li>
            <else />
            <li><label><input name="" type="checkbox" value="{$vo['id']}" title="{$vo['title']}">{$vo['value']}</label></li>
            </if>
            </foreach>
         </ul>
    </div>
</div>
<script type="text/javascript">

$(function () {

    var myDate = new Date()
    var y = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
    var m = myDate.getMonth(); //获取当前月份(0-11,0代表1月)
    var d = myDate.getDate(); //获取当前日(1-31)
    var w = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
    var h = myDate.getHours(); //获取当前小时数(0-23)
    var f = myDate.getMinutes(); //获取当前分钟数(0-59)
    var tmpArr = new Array('周日','周一','周二','周三','周四','周五','周六');
    var s = (m+1) + '月' + d + '日' + tmpArr[w] + ' ' + h + ':' + f;
    var s = y + '-' + (m+1) + '-' + d  + ' ' + h + ':' + f;
    $('#datetime').val(s);

    //项目选择折叠收起
    $('.diytree li label').click(function() {
        var isShow = $(this).parent().find("ul").is(":visible");
        if(isShow==false){
            $(this).find("img").attr("src","__PUBLIC__/home/images/ico-.png");
             $(this).parent().find("ul").slideDown();
        }
        else{
            $(this).find("img").attr("src","__PUBLIC__/home/images/ico+.png");
             $(this).parent().find("ul").slideUp();
        }
    });
    var isopen=1;
    $('.diytree .control').click(function() {
        if(isopen==1){
            $('.diytree img').attr("src","__PUBLIC__/home/images/ico+.png");
            $('.diytree li ul').slideUp();
            isopen=0;
        }
        else{
            $('.diytree img').attr("src","__PUBLIC__/home/images/ico-.png");
            $('.diytree li ul').slideDown();
            isopen=1;
        }
    });
    /*项目*/
    $('#trigger1').click(function() {
        $('.popbox').css('display','block');
    });
    $('.popbox .mclose').click(function() { 
        $('.popbox').css('display','none');
        checkitemval();
    });
    function checkitemval(){
        var ids = '';
        var names = '';
         $('.diytree input:checkbox:checked').each(function (index, item) {
            ids += $(this).val() + '|';
            names += $(this).attr("title") + '|';
            $("#trigger1").html(names);
        });
        ids = ids.replace(/\|$/gi,'');//去出末尾 |
        names = names.replace(/\|$/gi,'');//去出末尾 |
        //console.log(ids);
        //console.log(names);
        $('#xm').val(names);
        $('#xmid').val(ids);
    }

    /*项目*/
    // $.post('project', {param1: ''}, function(data) {
    //     console.log(data)
    //     var UplinkData = data;
    //     var mobileSelect1 = new MobileSelect({
    //         trigger: '#trigger1',
    //         title: '项目', 
    //         wheels: [{data : UplinkData}],
    //         callback:function(indexArr, data){
    //             //console.log(data[0].id); //返回选中的json数据
    //             //保存项目
    //             $('#xm').val(data[0].value+data[1].value+data[2].value);
    //             $('#xmid').val(data[0].id+','+data[1].id+','+data[2].id);
    //         } 
    //     });
    // },"json");
    
    /*日期*/
    var curr = new Date().getFullYear();
    var opt={};
    opt.date = {preset : 'date'};
    opt.datetime = {preset : 'datetime'};
    opt.time = {preset : 'time'};
    opt.default = {
        theme: 'android-holo light', //皮肤样式
        display: 'modal', //显示方式 
        mode: 'scroller', //日期选择模式
        // dateFormat: 'yy年mm月dd日DD',
        dateFormat: 'yy-mm-dd',
        lang: 'zh',
        showNow: true,
        nowText: "今天",
        stepMinute: 5,
        yearText: '年', monthText: '月', dayText: '日', //面板中年月日文字
        startYear: curr - 0, //开始年份
        endYear: curr + 1 //结束年份
    };
    $('#datetime').scroller('destroy').scroller($.extend(opt['datetime'], opt['default']));
    /*多选*/
    multselInit(); 
    multselInit2();

    $('.hright').click(function(){
        //内容
        var content = $('#content').val()   
        //项目
        var xm = $('#xm').val();
        var xmid = $('#xmid').val();
        if(!content){
            alert('请填写日程内容！');return false;
        }
        if(!xmid){
            alert('请选择所属项目！');return false;
        }
        //时间
        var str = $('#datetime').val();
        // var type = '';
        // if(str.indexOf('年',str)>-1){
        //     type = 1;
        //     str = str.replace(/年/g,'');
        // }else{
        //     type = 0;
        // }
        // str = str.replace(/日/g,'');
        // str = str.replace(/月/g,'');
        // str = str.replace(/周/g,'');
        // var arr = new Array('一','二','三','四','五','六','日');
        // for(j = 0; j < arr.length; j++) {
        //     str = str.replace(new RegExp(arr[j],'g'),'');
        // }
        //跟进人员
        var follow = $('#sel1').val();
        follow = follow.replace(/ /g,',');
        follow = follow.replace(/,$/gi,'');//去出末尾,
        //抄送人员
        var cc = $('#sel2').val();
        cc = cc.replace(/ /g,',');
        cc = cc.replace(/,$/gi,'');//去出末尾,
        //备注
        var remark = $('#remark').val();
        $.ajax({
            url :  "{:U('addTask')}",
            type : 'post',
            data : {
                'follow' : follow,
                'cc' : cc,
                'datetime' : str,
                'remark' : remark,
                'content' : content,
                'xm' : xm,
                'xmid' : xmid
            },
            dataType : 'json',
            success : function (data, status) {
                console.log(data)
                if(data.status){
                    location.href = data.url;
                }else{
                    alert(data.info);
                }
            },
            fail : function (err, status) {
                console.log(err)
            }
        })
    });
});
</script>
</body>
</html>